﻿<%@ WebHandler Language="C#" Class="LoadSelect" %>

using System;
using System.Web;
using LP580.CG;

public class LoadSelect : IHttpHandler {

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        string type = Utils.RF_str("t");
        string writeval = "";
        int id = Utils.RF_int("id");
        switch (type)
        {
            case "giftclass":
                writeval = GetGiftClassChild(id);
                break;
            case "area":
                writeval = GetArea(id);
                break;
            default:
                break;
        }
        context.Response.Write(writeval);
        context.Response.End();
    }

    public string GetGiftClassChild(int id)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        System.Collections.Generic.List<clsGiftProductClass> ls = new clsGiftProductClass(id).GetDirectChildCollection();
        foreach (clsGiftProductClass gpc in ls)
        {
            sb.AppendFormat("<option value='{0}'>{1}</option>", gpc.GiftProductClassID, gpc.GiftProductClassName);
        }
        return sb.ToString();
    }

    public string GetArea(int id)
    {
        DBase db = new DBase();
        string sql = string.Format("select ID,Name from Area_z where ParentID={0}", id);
        System.Data.IDataReader dr = db.ExecuteReader(sql);
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        while (dr.Read())
        {
            sb.AppendFormat("<option value='{0}'>{1}</option>", dr[0], dr[1]);
        }
        dr.Dispose();
        dr = null;
        db.CloseConn();
        db = null;
        return sb.ToString();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}